

import os

import mmcv
# using a pre-trained detector. 预训练配置
from mmcv import Config

from mmdet.datasets import build_dataset
from mmdet.models import build_detector
from mmdet.apis import train_detector, inference_detector, show_result_pyplot

root_path=r"/home/deepin/Documents/openmmlab/mmdetection/"

cfg_path=root_path+'mytest/KittiTinyDataset_learning/work_dir/KittiTinyDataset_cfgformat.py'

cfg = Config.fromfile(cfg_path) # 读取 保存的自定义 cfg py文件


# Build dataset 构建 数据集
datasets = [build_dataset(cfg.data.train)]

# Build the detector 构建 识别
model = build_detector(cfg.model)

# Add an attribute for visualization convenience 添加属性以方便可视化，模型的类别
model.CLASSES = datasets[0].CLASSES


# 推理 显示
img = mmcv.imread(root_path+'data/kitti_tiny/training/image_2/000000.jpeg')

model.cfg = cfg
result = inference_detector(model, img) # -------如何 把 训练完成的，进行推理，这个不知道  如何加载呢
show_result_pyplot(model, img, result,score_thr=0.9) #显示



